package com.zy.qudadid.presenter;

import com.zy.qudadid.model.IntegralOther;
import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.RefreshAndLoadMorePresenter;
import com.zy.qudadid.ui.view.IntegralOtherView;
import com.zy.qudadid.ui.view.ShopView;
import com.zy.qudadid.utils.TextUtil;

import java.util.ArrayList;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by liuchao on 2017/4/10.
 */

public class IntegralOtherPresenter extends RefreshAndLoadMorePresenter<IntegralOtherView> {
    @Override
    public void getData(int page, int count) {

    }

    public void getIntegral(String args,int tag){
        Subscription subscription=null;
        if(tag == 0) {
            subscription = Net.getService()
                    .getIntegralList(args)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<Res<ArrayList<IntegralOther>>>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onNext(Res<ArrayList<IntegralOther>> res) {
                            if (res.code == Const.OK) {
                                view.integralSuccess(res.datas);
                            } else {
                                view.integralError(res.message);
                            }
                        }
                    });
        }else if(tag == 1){
            subscription = Net.getService()
                    .getIntegralList()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<Res<ArrayList<IntegralOther>>>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onNext(Res<ArrayList<IntegralOther>> res) {
                            if (res.code == Const.OK) {
                                view.integralSuccess(res.datas);
                            } else {
                                view.integralError(res.message);
                            }
                        }
                    });
        }else if(tag == 2){
            subscription = Net.getService()
                    .getIntegralList2(args)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<Res<ArrayList<IntegralOther>>>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onNext(Res<ArrayList<IntegralOther>> res) {
                            if (res.code == Const.OK) {
                                view.integralSuccess(res.datas);
                            } else {
                                view.integralError(res.message);
                            }
                        }
                    });
        }
        addSubscription(subscription);
    }
}
